#!/usr/bin/perl
#Programmer: Rory Carmichael
#Purpose: move annoyingly named files into consistent naming format while maintaining backwards lut
#Usage: rename.pl <file list>

my %lut;
while (my $line = <>) {
	chomp $line;
	$lut{$line} = $line;
}

foreach $key (keys(%lut)) {
	$name = $lut{$key};
	$name =~ s/tag-//;
	$name =~ s/ORF//;
	@nparts = split(/[_\.\s+]/, $name);
	@actual = ();
	foreach my $bit (@nparts) {
		if ($bit !~ /^$/ && $bit !~ /new/ && $bit !~ /txt/ && $bit !~ /fasta/ && $bit !~ /pergene/ && $bit !~ /March/ && $bit !~ /^[0-9]+$/) {
			push (@actual, $bit);
		}
	}
	$lut{$key} = join("_", @actual) . ".fasta";
}
while (my ($key, $val) = each(%lut)) {
	if(-e $key) {
		print "$key\t$val\n";
		$key =~ s/ /\\ /g;
		`mv $key $val`;
	}
}
